// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_animation/test_page.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
  testWidgets('test page', (WidgetTester tester) async {
    // 构建widget
    await tester.pumpWidget(TestPage());
    // 往输入框中输入 hello
    await tester.enterText(find.byType(TextField), 'hello');
    // 点击 button 触发增加数据事件
    await tester.tap(find.byType(FloatingActionButton));
    // 让 widget 重绘
    await tester.pump();
    // 检测 text 是否添加到 List 中
    expect(find.text('hello'), findsOneWidget);
    // 测试滑动
    await tester.drag(find.byType(Dismissible), Offset(300, 0));
    // 页面会一直刷新，直到最后一帧绘制完成
    await tester.pumpAndSettle();

    ///Matchers
    /// findsOneWidget   验证找到有且只有一个widget
    /// findsNothing     验证没有可被查找的 widgets。
    /// findsWidgets     验证一个或多个 widgets 被找到。
    /// findsNWidgets    验证特定数量的 widgets 被找到。

    // 验证页面中是否还有 hello 这个 item
    expect(find.text('hello'), findsNothing);
  });
}
